from django.contrib.auth.models import Group,Permission
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.generics import ListAPIView

from apps.meiduo_admin.serializers.group import GroupSerializer, GroupPermissionSerializer
from apps.meiduo_admin.utils import PageNum


class GroupView(ModelViewSet):
    """
    获取用户组数据
    """
    # 指定序列化器
    serializer_class = GroupSerializer
    #　指定查询集
    queryset = Group.objects.all()
    # 指定分页器
    pagination_class = PageNum

    # 获取权限
    def simple(self,request):
        # 查询权限表
        data = Permission.objects.all()
        # 返回权限
        ser = GroupPermissionSerializer(data,many=True)
        return Response(ser.data)


# class GroupListAPIView(ListAPIView):
#     """
#     使用ListAPIView实现保存分组数据
#     """
#     # 指定序列化器
#     serializer_class = GroupPermissionSerializer
#     #　指定查询集
#     queryset = Permission.objects.all()